

package com.maoshi.shop.user.platform.controller;

import com.maoshi.shop.bean.model.UserExtension;
import com.maoshi.shop.common.annotation.SysLog;

import javax.validation.Valid;

import com.maoshi.shop.service.UserExtensionService;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.maoshi.shop.common.util.PageParam;
import com.baomidou.mybatisplus.core.metadata.IPage;


/**
 * 用户扩展信息
 *
 * @author LGH
 * @date 2020-02-26 16:03:14
 */
@RestController
@AllArgsConstructor
@RequestMapping("/user/userExtension" )
public class UserExtensionController {

    private final UserExtensionService userExtensionService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param userExtension 用户扩展信息
     * @return 分页数据
     */
    @GetMapping("/page" )
    public ResponseEntity<IPage<UserExtension>> getUserExtensionPage(PageParam<UserExtension> page, UserExtension userExtension) {
        return ResponseEntity.ok(userExtensionService.getPage(page,userExtension));
    }


    /**
     * 通过id查询用户扩展信息
     * @param userExtensionId id
     * @return 单个数据
     */
    @GetMapping("/info/{userExtensionId}" )
    public ResponseEntity<UserExtension> getById(@PathVariable("userExtensionId") Long userExtensionId) {
        return ResponseEntity.ok(userExtensionService.getById(userExtensionId));
    }

    /**
     * 新增用户扩展信息
     * @param userExtension 用户扩展信息
     * @return 是否新增成功
     */
    @SysLog("新增用户扩展信息" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('user:userExtension:save')" )
    public ResponseEntity<Boolean> save(@RequestBody @Valid UserExtension userExtension) {
        return ResponseEntity.ok(userExtensionService.save(userExtension));
    }

    /**
     * 修改用户扩展信息
     * @param userExtension 用户扩展信息
     * @return 是否修改成功
     */
    @SysLog("修改用户扩展信息" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('user:userExtension:update')" )
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid UserExtension userExtension) {
        return ResponseEntity.ok(userExtensionService.updateById(userExtension));
    }

    /**
     * 通过id删除用户扩展信息
     * @param userExtensionId id
     * @return 是否删除成功
     */
    @SysLog("删除用户扩展信息" )
    @DeleteMapping("/{userExtensionId}" )
    @PreAuthorize("@pms.hasPermission('user:userExtension:delete')" )
    public ResponseEntity<Boolean> removeById(@PathVariable Long userExtensionId) {
        return ResponseEntity.ok(userExtensionService.removeById(userExtensionId));
    }

}
